<?php
class App implements \Yaf\Route_Interface
{
    public function route($request)
    {
        $path = $request->getRequestUri();
        $path = $this->parseUrlPath($path);
        $app = !empty($path) ? array_shift($path) : 'index';
        $controller = !empty($path) ? array_shift($path) : 'index';
        $action = !empty($path) ? array_shift($path) : 'index';
        // $request->setModuleName($app);
        $request->setControllerName($controller);
        $request->setActionName($action);
        return true;

    }
    public function assemble(array $info, array $query = null)
    {
    }
    /**
     * 解析URL的pathinfo参数
     * @access public
     * @param  string $url URL地址
     * @return array
     */
    protected function parseUrlPath(string $url): array
    {
        //$url = str_replace('index.php', '', $url);
        $url = trim($url, '/');
        if (empty($url)) {
            return [];
        }
        if (strpos($url, '/')) {
            // [控制器/操作]
            $path = explode('/', $url);
        } else {
            $path = [$url];
        }

        return $path;
    }
}
